package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.dao.GiftDao;
import com.feri.rbacsys.entity.Gift;

import com.feri.rbacsys.service.intf.GiftService;
import com.feri.rbacsys.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Gift)表服务实现类
 *
 * @author makejava
 * @since 2023-03-27 21:00:20
 */
@Service
public class GiftServiceImpl extends ServiceImpl<GiftDao, Gift> implements GiftService {

    @Resource
    private GiftDao dao;

    @Override
    public R queryPage(int page, int size) {
        return R.ok(dao.selectPage(new Page<>(page,size),null));
    }

    @Override
    public R queryWhere(Gift bo) {
        //1.实例化 条件构造器对象
        QueryWrapper<Gift> queryWrapper=new QueryWrapper<>();
        //2.动态设置条件
        if(bo.getId()!=null){
            queryWrapper.like("id",bo.getId());
        }
        if(StringUtils.hasLength(bo.getCreator())){
            queryWrapper.like("creator",bo.getCreator());
        }
        //排序
        queryWrapper.orderByDesc("id");

        //3.执行查询
        return new R(0,"OK",dao.selectList(queryWrapper));
    }

    @Override
    public R selectGiftDetail(int id) {
        return R.ok(dao.selectGiftDetail(id));
    }


}

